package com.xms.security.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.security.core.RoleMemberShipType;
import com.xms.security.entity.RoleMemberShip;
import com.xms.security.service.role.IRoleMemberShipService;
import com.xms.utils.UUIDUtil;
import com.xms.web.framework.controller.ApiBaseController;
import com.xms.web.framework.model.JsonResultObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author migo
 * @since 2021-08-29
 */
@RestController
@RequestMapping("/{org}/api/security/systemuserroles")
public class SystemuserRolesController extends ApiBaseController {
    private IRoleMemberShipService _roleMemberShipService;

    @Autowired
    public SystemuserRolesController(IRoleMemberShipService roleMemberShipService) {
        _roleMemberShipService = roleMemberShipService;
    }

    @ApiOperation("获取用户角色列表")
    @GetMapping("get")
    public JsonResultObject getUserRoles(@RequestParam(value="userid", required = true) UUID userid){
        if(UUIDUtil.isEmpty(userid)){
            return JNotSpecifiedParams("userid");
        }

        return JOk(_roleMemberShipService.list(new LambdaQueryWrapper<RoleMemberShip>()
                .eq(RoleMemberShip::getMemberid, userid).eq(RoleMemberShip::getTypecode, RoleMemberShipType.USER.value())));
    }
}
